using Godot;
using System;
using Godot.Collections;

public partial class MetaMenu : CanvasLayer
{
	[Export]
	Array<MetaUpgrade> upgrades;
	PackedScene metaUpgradeCardScene = GD.Load<PackedScene>("res://scenes/ui/meta_upgrade_card.tscn");

	GridContainer gridContainer;
	ScreenTransition screenTransition;

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		screenTransition = GetNode<ScreenTransition>("/root/ScreenTransition");
		gridContainer = GetNode<GridContainer>("%GridContainer");
		foreach(Node children in gridContainer.GetChildren()){
			children.QueueFree();
		}

		GetNode<Button>("%BackButton").Pressed += OnBackPressed;

		foreach(MetaUpgrade upgrade in upgrades){
			var metaUpgradeCardInstance = metaUpgradeCardScene.Instantiate() as MetaUpgradeCard;
			gridContainer.AddChild(metaUpgradeCardInstance);
			metaUpgradeCardInstance.SetMetaUpgrade(upgrade);
		}
	}

	public void OnBackPressed(){
		screenTransition.TransitionToScene("res://scenes/ui/main_menu.tscn");
	}
}
